<script>
export default {
  name: 'CarbonNeutralityActualSituation',
  props: {
    pageData: {
      required: false,
      default: {}
    },
    projectList: {
      required: false,
      default: []
    }
  },
  data() {
    return {
    }
  },
  methods: {
    getProjectName(projectId) {
      return this.projectList.find(project => project.value === projectId)?.label
    },
    getMaxRowByProjectAndField(projectId, field) {
      const list = this.pageData.projectData[projectId] || []
      if (list.length === 0) {
        return {}
      }
      return list.slice().sort((a, b) => b[field] - a[field])[0]
    },
    getMinRowByProjectAndField(projectId, field) {
      const list = this.pageData.projectData[projectId] || []
      if (list.length === 0) {
        return {}
      }
      return list.slice().sort((a, b) => a[field] - b[field])[0]
    }
  }
}
</script>

<template>
  <div>
    <div>
      <h2>3、碳中和实际情况</h2>
      <table style="width: 60%; margin: 0 15%">
        <thead>
        <tr>
          <th>所属项目</th>
          <th>实际碳排（kgCO2）</th>
          <th>实际碳减（kgCO2）</th>
          <th>实际碳汇（kgCO2）</th>
          <th>实际碳中和（kgCO2）</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="item in pageData.projectTotalList" :key="item.id">
          <td>{{ getProjectName(item.sceneProjectId) }}</td>
          <td>{{ item.actualCarbonEmissions }}</td>
          <td>{{ item.actualCarbonZero }}</td>
          <td>{{ item.actualCarbonSequestration }}</td>
          <td>{{ item.actualCarbonNeutrality }}</td>
        </tr>
        </tbody>
      </table>
      <div style="margin: 0 15%">
        <p v-for="item in pageData.projectTotalList">{{ getProjectName(item.sceneProjectId) }}在
          {{ pageData.startDate }}-{{ pageData.endDate }}实际碳中和数据，
          实际碳中和总量为{{ item.actualCarbonNeutrality}} kgCO2。
          其中实际碳排总量为{{ item.actualCarbonEmissions }} kgCO2，
          实际碳减总量为{{ item.actualCarbonZero }} kgCO2，
          实际碳汇为{{ item.actualCarbonSequestration }} kgCO2。</p>
      </div>
    </div>
    <div v-for="(projectId,index) in Object.keys(pageData.projectData)" :key="projectId" class="project-item">
      <h3>3.{{ index + 1 }} {{ getProjectName(projectId) }}碳中和时间实际情况</h3>
      <table style="width: 60%; margin: 0 15%">
        <thead>
        <tr>
          <th>数据时间</th>
          <th>实际碳排（kgCO2）</th>
          <th>实际碳减（kgCO2）</th>
          <th>实际碳汇（kgCO2）</th>
          <th>实际碳中和（kgCO2）</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="item in pageData.projectData[projectId]" :key="item.solidifyDate">
          <td>{{ item.solidifyDate }}</td>
          <td>{{ item.actualCarbonEmissions }}</td>
          <td>{{ item.actualCarbonZero }}</td>
          <td>{{ item.actualCarbonSequestration }}</td>
          <td>{{ item.actualCarbonNeutrality }}</td>
        </tr>
        </tbody>
      </table>
      <div style="margin: 0 10%">
        <p>展示和比较在不同日期下，项目的碳排放量、碳减排量、碳汇量以及碳中和量的实际情况。
          {{ getProjectName(projectId) }}在{{ pageData.startDate }}-{{ pageData.endDate }}中，
          {{ getMaxRowByProjectAndField(projectId, 'actualCarbonEmissions').solidifyDate }}的实际碳排最高，为{{ getMaxRowByProjectAndField(projectId,'actualCarbonEmissions').actualCarbonEmissions }} kgCO2;
          {{ getMinRowByProjectAndField(projectId, 'actualCarbonEmissions').solidifyDate }}实际碳排最低，为 {{getMinRowByProjectAndField(projectId, 'actualCarbonEmissions').actualCarbonEmissions}} kgCO2。
          {{ getMaxRowByProjectAndField(projectId, 'actualCarbonZero').solidifyDate }}的实际碳减最高，为 {{ getMaxRowByProjectAndField(projectId, 'actualCarbonZero').actualCarbonZero }}kgCO2;
          {{ getMinRowByProjectAndField(projectId, 'actualCarbonZero').solidifyDate }}的实际碳减最低，为{{ getMinRowByProjectAndField(projectId, 'actualCarbonZero').actualCarbonZero }} kgCO2。
          {{ getMaxRowByProjectAndField(projectId, 'actualCarbonSequestration').solidifyDate }}的实际碳汇最高，为 {{ getMaxRowByProjectAndField(projectId, 'actualCarbonSequestration').actualCarbonSequestration }} kgCO2;
          {{ getMinRowByProjectAndField(projectId, 'actualCarbonSequestration').solidifyDate }}碳汇最低，为{{ getMinRowByProjectAndField(projectId, 'actualCarbonSequestration').actualCarbonSequestration }}kgCO2。
          {{ getMaxRowByProjectAndField(projectId, 'actualCarbonNeutrality').solidifyDate }}的实际碳中和最高，为{{ getMaxRowByProjectAndField(projectId, 'actualCarbonNeutrality').actualCarbonNeutrality }}kgCO2;
          {{ getMinRowByProjectAndField(projectId, 'actualCarbonNeutrality').solidifyDate }}碳中和最低，为{{ getMinRowByProjectAndField(projectId, 'actualCarbonNeutrality').actualCarbonNeutrality }}kgCO2。</p></p>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
table {
  border-collapse: collapse;
  width: 80%;
  margin: 0 10%;
  font-size: 16px;
  font-weight: 500;

  th {
    border: 1px solid rgba(0, 0, 0, 0.6);
    padding: 6px 10px;
    background-color: #029590;
    text-align: center;
  }

  td {
    border: 1px solid #000000;
    padding: 6px 10px;
    text-align: center;
  }
}

.project-item {
  margin: 0 5%;

}

p {
  text-indent: 2em;
  line-height: 24px;
}
</style>
